import { getData } from '@vimi/utils-api'
const tableName = 'system_enum'
const enumParams = {
  // 企业机构级别
  businessLevel: {
    'enum_field.eq': 'credit_agency_info.org_region_lever',
    'cond_value.eq': 2,
  },
  // 银行分类
  bankClass: {
    'enum_field.eq': 'credit_agency_info.agency_type_sub',
  },
  // 十二大产业分类
  mainBusiness: {
    'enum_field.eq': 'datum_one_county_industry.main_business',
  },
  // 行业分类
  parentMainBusiness: {
    'enum_field.eq': 'datum_one_county_industry.parent_main_business',
  },
  // 贷款用途
  fundsUseDir: {
    'enum_field.eq': 'datum_one_county_industry.funds_use_dir',
  },
  productChannel: {
    'enum_field.eq': 'credit.product_channel',
  },
  fiveIndClass: {
    'enum_field.eq': 'credit.five_ind_class',
  },
}
export function getEnum(params, order = {}) {
  return new Promise(resolve => {
    if (!params || !enumParams[params]) {
      resolve({ enum: {}, data: [] })
    }
    getData('credit', tableName, enumParams[params], order)
      .then(res => {
        const options = res?.data ?? []
        const obj = {}
        options.forEach(item => {
          obj[item.enum_key] = item.enum_value
        })
        resolve({ enum: obj, data: options })
      })
      .catch(() => {
        resolve({ enum: {}, data: [] })
      })
  })
}
